<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="年度采购计划号" prop="purPlanNoY">
        <el-input
          v-model="queryParams.purPlanNoY"
          placeholder="请输入年度采购计划号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="年度采购计划数量" prop="purPlanNumY">
        <el-input
          v-model="queryParams.purPlanNumY"
          placeholder="请输入年度采购计划数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="季度采购计划号" prop="purPlanNoJ">
        <el-input
          v-model="queryParams.purPlanNoJ"
          placeholder="请输入季度采购计划号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="季度采购计划数量" prop="purPlanNumJ">
        <el-input
          v-model="queryParams.purPlanNumJ"
          placeholder="请输入季度采购计划数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="月度采购计划号" prop="purPlanNoM">
        <el-input
          v-model="queryParams.purPlanNoM"
          placeholder="请输入月度采购计划号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="月度采购计划数量" prop="purPlanNumM">
        <el-input
          v-model="queryParams.purPlanNumM"
          placeholder="请输入月度采购计划数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="临时采购计划号" prop="tempPurNo">
        <el-input
          v-model="queryParams.tempPurNo"
          placeholder="请输入临时采购计划号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="临时采购计划数量" prop="tempPurNum">
        <el-input
          v-model="queryParams.tempPurNum"
          placeholder="请输入临时采购计划数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="要货单号" prop="yhNo">
        <el-input
          v-model="queryParams.yhNo"
          placeholder="请输入要货单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="公司代码" prop="factoryCode">
        <el-input
          v-model="queryParams.factoryCode"
          placeholder="请输入公司代码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="公司名称" prop="factoryName">
        <el-input
          v-model="queryParams.factoryName"
          placeholder="请输入公司名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="ASN编号" prop="asnNo">
        <el-input
          v-model="queryParams.asnNo"
          placeholder="请输入ASN编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="子图号" prop="itemChildNo">
        <el-input
          v-model="queryParams.itemChildNo"
          placeholder="请输入子图号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料名称" prop="materialName">
        <el-input
          v-model="queryParams.materialName"
          placeholder="请输入物料名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料计量单位" prop="materialUnit">
        <el-input
          v-model="queryParams.materialUnit"
          placeholder="请输入物料计量单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="条码号" prop="barcode">
        <el-input
          v-model="queryParams.barcode"
          placeholder="请输入条码号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="合同号" prop="contractNo">
        <el-input
          v-model="queryParams.contractNo"
          placeholder="请输入合同号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="合同份额" prop="contractShare">
        <el-input
          v-model="queryParams.contractShare"
          placeholder="请输入合同份额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="合同数量" prop="contractNum">
        <el-input
          v-model="queryParams.contractNum"
          placeholder="请输入合同数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="托管属性" prop="trusteeshipProp">
        <el-input
          v-model="queryParams.trusteeshipProp"
          placeholder="请输入托管属性"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="要货数量" prop="yhNum">
        <el-input
          v-model="queryParams.yhNum"
          placeholder="请输入要货数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="送货数量" prop="shNum">
        <el-input
          v-model="queryParams.shNum"
          placeholder="请输入送货数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="入库数量" prop="rkNum">
        <el-input
          v-model="queryParams.rkNum"
          placeholder="请输入入库数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="合格数量" prop="qualifiedNum">
        <el-input
          v-model="queryParams.qualifiedNum"
          placeholder="请输入合格数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="退货数量" prop="returnNum">
        <el-input
          v-model="queryParams.returnNum"
          placeholder="请输入退货数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="要货单位" prop="yhWork">
        <el-input
          v-model="queryParams.yhWork"
          placeholder="请输入要货单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="要货时间" prop="yhTime">
        <el-date-picker clearable
          v-model="queryParams.yhTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择要货时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="订货单位" prop="dhWork">
        <el-input
          v-model="queryParams.dhWork"
          placeholder="请输入订货单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物流单位" prop="logisticsWork">
        <el-input
          v-model="queryParams.logisticsWork"
          placeholder="请输入物流单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订货仓库" prop="dhWarehouse">
        <el-input
          v-model="queryParams.dhWarehouse"
          placeholder="请输入订货仓库"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收货人编码" prop="consigneeCode">
        <el-input
          v-model="queryParams.consigneeCode"
          placeholder="请输入收货人编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收货位" prop="consigneeW">
        <el-input
          v-model="queryParams.consigneeW"
          placeholder="请输入收货位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收货地址" prop="consigneeAddress">
        <el-input
          v-model="queryParams.consigneeAddress"
          placeholder="请输入收货地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="供货单位" prop="supplyWork">
        <el-input
          v-model="queryParams.supplyWork"
          placeholder="请输入供货单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="供货地址" prop="supplyAddress">
        <el-input
          v-model="queryParams.supplyAddress"
          placeholder="请输入供货地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="生产周期" prop="proCycle">
        <el-input
          v-model="queryParams.proCycle"
          placeholder="请输入生产周期"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="供应商运输距离" prop="supplyKm">
        <el-input
          v-model="queryParams.supplyKm"
          placeholder="请输入供应商运输距离"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="供应商运输时间" prop="supplyTpTime">
        <el-date-picker clearable
          v-model="queryParams.supplyTpTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择供应商运输时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="供货周期" prop="deliveryCycle">
        <el-input
          v-model="queryParams.deliveryCycle"
          placeholder="请输入供货周期"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="月订单数量" prop="orderQuantityMon">
        <el-input
          v-model="queryParams.orderQuantityMon"
          placeholder="请输入月订单数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="月完成数量" prop="orderQuantityFinishMon">
        <el-input
          v-model="queryParams.orderQuantityFinishMon"
          placeholder="请输入月完成数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="月度供货未完成比率" prop="nofinishRateMon">
        <el-input
          v-model="queryParams.nofinishRateMon"
          placeholder="请输入月度供货未完成比率"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单箱容量" prop="oneCapacity">
        <el-input
          v-model="queryParams.oneCapacity"
          placeholder="请输入单箱容量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="包装尺寸" prop="packageSize">
        <el-input
          v-model="queryParams.packageSize"
          placeholder="请输入包装尺寸"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="包装材质" prop="packageTexture">
        <el-input
          v-model="queryParams.packageTexture"
          placeholder="请输入包装材质"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单箱重量" prop="oneWeight">
        <el-input
          v-model="queryParams.oneWeight"
          placeholder="请输入单箱重量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['sales:purchaseOrder:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['sales:purchaseOrder:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['sales:purchaseOrder:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['sales:purchaseOrder:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="info"
            plain
            icon="el-icon-upload2"
            size="mini"
            @click="handleImport"
        >导入</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="purchaseOrderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="id" />
      <el-table-column label="年度采购计划号" align="center" prop="purPlanNoY" />
      <el-table-column label="年度采购计划数量" align="center" prop="purPlanNumY" />
      <el-table-column label="季度采购计划号" align="center" prop="purPlanNoJ" />
      <el-table-column label="季度采购计划数量" align="center" prop="purPlanNumJ" />
      <el-table-column label="月度采购计划号" align="center" prop="purPlanNoM" />
      <el-table-column label="月度采购计划数量" align="center" prop="purPlanNumM" />
      <el-table-column label="临时采购计划号" align="center" prop="tempPurNo" />
      <el-table-column label="临时采购计划数量" align="center" prop="tempPurNum" />
      <el-table-column label="要货单号" align="center" prop="yhNo" />
      <el-table-column label="公司代码" align="center" prop="factoryCode" />
      <el-table-column label="公司名称" align="center" prop="factoryName" />
      <el-table-column label="ASN编号" align="center" prop="asnNo" />
      <el-table-column label="子图号" align="center" prop="itemChildNo" />
      <el-table-column label="物料名称" align="center" prop="materialName" />
      <el-table-column label="物料计量单位" align="center" prop="materialUnit" />
      <el-table-column label="条码号" align="center" prop="barcode" />
      <el-table-column label="合同号" align="center" prop="contractNo" />
      <el-table-column label="合同份额" align="center" prop="contractShare" />
      <el-table-column label="合同数量" align="center" prop="contractNum" />
      <el-table-column label="托管属性" align="center" prop="trusteeshipProp" />
      <el-table-column label="要货数量" align="center" prop="yhNum" />
      <el-table-column label="送货数量" align="center" prop="shNum" />
      <el-table-column label="入库数量" align="center" prop="rkNum" />
      <el-table-column label="合格数量" align="center" prop="qualifiedNum" />
      <el-table-column label="退货数量" align="center" prop="returnNum" />
      <el-table-column label="要货类型" align="center" prop="yhType" />
      <el-table-column label="要货单位" align="center" prop="yhWork" />
      <el-table-column label="要货时间" align="center" prop="yhTime" width="180"/>
      <el-table-column label="订货单位" align="center" prop="dhWork" />
      <el-table-column label="物流单位" align="center" prop="logisticsWork" />
      <el-table-column label="订货仓库" align="center" prop="dhWarehouse" />
      <el-table-column label="收货人编码" align="center" prop="consigneeCode" />
      <el-table-column label="收货位" align="center" prop="consigneeW" />
      <el-table-column label="收货地址" align="center" prop="consigneeAddress" />
      <el-table-column label="供货单位" align="center" prop="supplyWork" />
      <el-table-column label="供货地址" align="center" prop="supplyAddress" />
      <el-table-column label="生产周期" align="center" prop="proCycle" />
      <el-table-column label="供应商运输距离" align="center" prop="supplyKm" />
      <el-table-column label="供应商运输时间" align="center" prop="supplyTpTime" width="180"/>
      <el-table-column label="供货周期" align="center" prop="deliveryCycle" />
      <el-table-column label="月订单数量" align="center" prop="orderQuantityMon" />
      <el-table-column label="月完成数量" align="center" prop="orderQuantityFinishMon" />
      <el-table-column label="月度供货未完成比率" align="center" prop="nofinishRateMon" />
      <el-table-column label="单箱容量" align="center" prop="oneCapacity" />
      <el-table-column label="包装尺寸" align="center" prop="packageSize" />
      <el-table-column label="包装材质" align="center" prop="packageTexture" />
      <el-table-column label="单箱重量" align="center" prop="oneWeight" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['sales:purchaseOrder:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['sales:purchaseOrder:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改采购订单管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="90px">
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="年度采购计划号" prop="purPlanNoY">
              <el-input v-model="form.purPlanNoY" placeholder="请输入年度采购计划号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="年度采购计划数量" prop="purPlanNumY">
              <el-input v-model="form.purPlanNumY" placeholder="请输入年度采购计划数量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="季度采购计划号" prop="purPlanNoJ">
              <el-input v-model="form.purPlanNoJ" placeholder="请输入季度采购计划号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="季度采购计划数量" prop="purPlanNumJ">
              <el-input v-model="form.purPlanNumJ" placeholder="请输入季度采购计划数量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="月度采购计划号" prop="purPlanNoM">
              <el-input v-model="form.purPlanNoM" placeholder="请输入月度采购计划号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="月度采购计划数量" prop="purPlanNumM">
              <el-input v-model="form.purPlanNumM" placeholder="请输入月度采购计划数量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="临时采购计划号" prop="tempPurNo">
              <el-input v-model="form.tempPurNo" placeholder="请输入临时采购计划号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="临时采购计划数量" prop="tempPurNum">
              <el-input v-model="form.tempPurNum" placeholder="请输入临时采购计划数量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="要货单号" prop="yhNo">
              <el-input v-model="form.yhNo" placeholder="请输入要货单号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="公司代码" prop="factoryCode">
              <el-input v-model="form.factoryCode" placeholder="请输入公司代码" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="公司名称" prop="factoryName">
              <el-input v-model="form.factoryName" placeholder="请输入公司名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="ASN编号" prop="asnNo">
              <el-input v-model="form.asnNo" placeholder="请输入ASN编号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="子图号" prop="itemChildNo">
              <el-input v-model="form.itemChildNo" placeholder="请输入子图号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="物料名称" prop="materialName">
              <el-input v-model="form.materialName" placeholder="请输入物料名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="物料计量单位" prop="materialUnit">
              <el-input v-model="form.materialUnit" placeholder="请输入物料计量单位" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="条码号" prop="barcode">
              <el-input v-model="form.barcode" placeholder="请输入条码号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="合同号" prop="contractNo">
              <el-input v-model="form.contractNo" placeholder="请输入合同号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="合同份额" prop="contractShare">
              <el-input v-model="form.contractShare" placeholder="请输入合同份额" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="合同数量" prop="contractNum">
              <el-input v-model="form.contractNum" placeholder="请输入合同数量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="托管属性" prop="trusteeshipProp">
              <el-input v-model="form.trusteeshipProp" placeholder="请输入托管属性" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="要货数量" prop="yhNum">
              <el-input v-model="form.yhNum" placeholder="请输入要货数量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="送货数量" prop="shNum">
              <el-input v-model="form.shNum" placeholder="请输入送货数量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="入库数量" prop="rkNum">
              <el-input v-model="form.rkNum" placeholder="请输入入库数量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="合格数量" prop="qualifiedNum">
              <el-input v-model="form.qualifiedNum" placeholder="请输入合格数量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="退货数量" prop="returnNum">
              <el-input v-model="form.returnNum" placeholder="请输入退货数量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="要货单位" prop="yhWork">
              <el-input v-model="form.yhWork" placeholder="请输入要货单位" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="要货时间" prop="yhTime">
              <el-date-picker clearable
                v-model="form.yhTime"
                type="date"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="请选择要货时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="订货单位" prop="dhWork">
              <el-input v-model="form.dhWork" placeholder="请输入订货单位" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="物流单位" prop="logisticsWork">
              <el-input v-model="form.logisticsWork" placeholder="请输入物流单位" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="订货仓库" prop="dhWarehouse">
              <el-input v-model="form.dhWarehouse" placeholder="请输入订货仓库" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="收货人编码" prop="consigneeCode">
              <el-input v-model="form.consigneeCode" placeholder="请输入收货人编码" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="收货位" prop="consigneeW">
              <el-input v-model="form.consigneeW" placeholder="请输入收货位" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="收货地址" prop="consigneeAddress">
              <el-input v-model="form.consigneeAddress" placeholder="请输入收货地址" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="供货单位" prop="supplyWork">
              <el-input v-model="form.supplyWork" placeholder="请输入供货单位" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="供货地址" prop="supplyAddress">
              <el-input v-model="form.supplyAddress" placeholder="请输入供货地址" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="生产周期" prop="proCycle">
              <el-input v-model="form.proCycle" placeholder="请输入生产周期" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="供应商运输距离" prop="supplyKm">
              <el-input v-model="form.supplyKm" placeholder="请输入供应商运输距离" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="供应商运输时间" prop="supplyTpTime">
              <el-date-picker clearable
                v-model="form.supplyTpTime"
                type="date"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="请选择供应商运输时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="供货周期" prop="deliveryCycle">
              <el-input v-model="form.deliveryCycle" placeholder="请输入供货周期" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="月订单数量" prop="orderQuantityMon">
              <el-input v-model="form.orderQuantityMon" placeholder="请输入月订单数量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="月完成数量" prop="orderQuantityFinishMon">
              <el-input v-model="form.orderQuantityFinishMon" placeholder="请输入月完成数量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="月度供货未完成比率" prop="nofinishRateMon">
              <el-input v-model="form.nofinishRateMon" placeholder="请输入月度供货未完成比率" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="单箱容量" prop="oneCapacity">
              <el-input v-model="form.oneCapacity" placeholder="请输入单箱容量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="包装尺寸" prop="packageSize">
              <el-input v-model="form.packageSize" placeholder="请输入包装尺寸" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="包装材质" prop="packageTexture">
              <el-input v-model="form.packageTexture" placeholder="请输入包装材质" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="单箱重量" prop="oneWeight">
              <el-input v-model="form.oneWeight" placeholder="请输入单箱重量" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
          ref="upload"
          :limit="1"
          accept=".xlsx, .xls"
          :headers="upload.headers"
          :action="upload.url + '?updateSupport=' + upload.updateSupport"
          :disabled="upload.isUploading"
          :on-progress="handleFileUploadProgress"
          :on-success="handleFileSuccess"
          :auto-upload="false"
          drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <!--  <div class="el-upload__tip" slot="tip">
              <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的用户数据
            </div>-->
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPurchaseOrder, getPurchaseOrder, delPurchaseOrder, addPurchaseOrder, updatePurchaseOrder } from "@/api/sales/purchaseOrder";
import {getToken} from "@/utils/auth";
export default {
  name: "PurchaseOrder",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 采购订单管理表格数据
      purchaseOrderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        purPlanNoY: null,
        purPlanNumY: null,
        purPlanNoJ: null,
        purPlanNumJ: null,
        purPlanNoM: null,
        purPlanNumM: null,
        tempPurNo: null,
        tempPurNum: null,
        yhNo: null,
        factoryCode: null,
        factoryName: null,
        asnNo: null,
        itemChildNo: null,
        materialName: null,
        materialUnit: null,
        barcode: null,
        contractNo: null,
        contractShare: null,
        contractNum: null,
        trusteeshipProp: null,
        yhNum: null,
        shNum: null,
        rkNum: null,
        qualifiedNum: null,
        returnNum: null,
        yhType: null,
        yhWork: null,
        yhTime: null,
        dhWork: null,
        logisticsWork: null,
        dhWarehouse: null,
        consigneeCode: null,
        consigneeW: null,
        consigneeAddress: null,
        supplyWork: null,
        supplyAddress: null,
        proCycle: null,
        supplyKm: null,
        supplyTpTime: null,
        deliveryCycle: null,
        orderQuantityMon: null,
        orderQuantityFinishMon: null,
        nofinishRateMon: null,
        oneCapacity: null,
        packageSize: null,
        packageTexture: null,
        oneWeight: null
      },
      upload: {
        // 是否显示弹出层
        open: false,
        // 弹出层标题
        title: "导入`purchaseOrder`信息",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/sales/purchaseOrder/importData"
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询采购订单管理列表 */
    getList() {
      this.loading = true;
      listPurchaseOrder(this.queryParams).then(response => {
        this.purchaseOrderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        purPlanNoY: null,
        purPlanNumY: null,
        purPlanNoJ: null,
        purPlanNumJ: null,
        purPlanNoM: null,
        purPlanNumM: null,
        tempPurNo: null,
        tempPurNum: null,
        yhNo: null,
        factoryCode: null,
        factoryName: null,
        asnNo: null,
        itemChildNo: null,
        materialName: null,
        materialUnit: null,
        barcode: null,
        contractNo: null,
        contractShare: null,
        contractNum: null,
        trusteeshipProp: null,
        yhNum: null,
        shNum: null,
        rkNum: null,
        qualifiedNum: null,
        returnNum: null,
        yhType: null,
        yhWork: null,
        yhTime: null,
        dhWork: null,
        logisticsWork: null,
        dhWarehouse: null,
        consigneeCode: null,
        consigneeW: null,
        consigneeAddress: null,
        supplyWork: null,
        supplyAddress: null,
        proCycle: null,
        supplyKm: null,
        supplyTpTime: null,
        deliveryCycle: null,
        orderQuantityMon: null,
        orderQuantityFinishMon: null,
        nofinishRateMon: null,
        oneCapacity: null,
        packageSize: null,
        packageTexture: null,
        oneWeight: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加采购订单管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getPurchaseOrder(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改采购订单管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updatePurchaseOrder(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPurchaseOrder(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除数据？').then(function() {
        return delPurchaseOrder(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('sales/purchaseOrder/export', {
        ...this.queryParams
      }, `purchaseOrder_${new Date().getTime()}.xlsx`)
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "采购订单管理导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('sales/purchaseOrder/importTemplate', {
      }, `采购订单管理模板.xlsx`)
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },
  }
};
</script>
